#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include "lws_segger.h"

using namespace std;
using namespace LWS;

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
	printf("test_segger data_path\n");
	return -1;
    }

    if(lws_init(argv[1], LWS_ATOM_RECOG | LWS_PERSON_RECOG | LWS_LOCATION_RECOG | LWS_NUMTIME_RECOG | LWS_POSTAG)) {
	void *segger = lws_create_segger();
	if(segger == NULL) {
	    printf("create segger fail!\n");
	    return -1;
	}

	string input;
	printf("please input text for word segment:\n");
	getline(cin, input);

	while(input != "quit") {
	    if(lws_segment(segger, input.c_str())) {
		printf("word segment and output the result:\n");
		for(int i = 0; i < lws_word_count(segger); i ++) {
		    printf("%s/%s[%d] ", lws_get_word(segger, i), lws_get_pos(segger, i), lws_get_position(segger, i));
		}
		lws_destroy_segger(segger);

		segger = lws_create_segger();
		if(segger == NULL) {
		    printf("create segger fail!\n");
		    return -1;
		}

		printf("\n\nplease input text for word segment:\n");
		getline(cin, input);
	    } else {
		printf("segment fail!\n");
		return -1;
	    }
	}

	lws_destroy_segger(segger);
    } else {
	printf("init fail!\n");
	return -1;
    }

    return 0;
}
